<?php

use swap\visitor;
use swap\service_except;
use swap\check_failed;
use swap\lazy_checker;

class resume_controller extends \swap\controller {
	
	public static $layout = 'my';
    
    public static function before_run() {
        self::role('user', 'redirect_to', 'my-site/login');
    }
	
	public static function index_action() {
		self::show_page();
	}
	
	
    // 创建简历
    public static function do_new_action() {
        $user_id = visitor::get_role_id('user');
        $user_limit = user_limit_model::get_one(array('user_id' => $user_id));
        self::set('resume_count', $user_limit->resume_count);
        // 核实简历数量
        try {
            user_limit_service::check_resume_count($user_limit->resume_count);
        } catch (service_except $se) {
            self::json_result(false, $se->get_msg());
        }
        // 新建简历
        $id = resume_service::new_resume_for($user_id);
        // 跳转
        self::redirect_to('my-resume/step1?id=' . $id);
    }
    // 步骤1
    public static function step1_action() {
		$email = visitor::get_role_var('user', 'email');
		self::set('email', $email);
        
		self::show_page();
	}
	
	//教育与工作
	public static function experience_action(){
		self::show_page();
	}
	
	//工作经验
	public static function work_experience_action(){
		self::show_page();
	}
	
	//附加信息
	public static function addition_action(){
		self::show_page();
	}


	//编辑简历
	public static function edit_action() {
		self::show_page();
	}
	
	// 用户信息
	public static function user_info_action() {
        $resume = self::check_resume_id();
        self::set('resume', $resume);
        
		self::show_page();
	}
	
	// 自我评价
	public static function myself_action() {
		self::show_page();
	}
    
    
    protected static function check_resume_id() {
        $id = g_int('id', 0);
        $resume = resume_model::get_by_id($id);
        if ($resume === null) {
            self::forward_404('非法请求');
        } 
        return $resume;
    }
		
}